<?php

/**
 * 智能名片
 */

namespace app\api\controller;

use app\common\controller\ApiController;
use think\Exception;
use app\api\model\Customer as CustomerModel;
use app\api\model\AgentAttention;
use app\api\model\AgentRemind;
use app\common\lib\RespCode;

class Customer extends ApiController {

    protected $isArrayResult = ['getinteractionlist','getHouseInteractionList','gettimerechouse'];

    /**
     * 客户列表
     */
    public function getCustomerList() {
        try {
            $params = $this->checkParams ('page');
            $CustomerModel = new CustomerModel();
            $pageSize=10;//每页显示数据数
            $data = $CustomerModel->getCustomerList ($params,$pageSize);
            return $this->resData ('success', $data);
        } catch (Exception $e) {
            return $this->resErr ($e->getMessage (), $e->getCode ());
        }
    }

    /**
     * 客户信息展示
     * @return false|string
     */
    public function getCustomerInfo() {
        try {
            $params = $this->checkParams ('agent_user_id');
            $CustomerModel = new CustomerModel();
            $data = $CustomerModel->getCustomerInfo ($params);
            return $this->resData ('success', $data);
        } catch (Exception $e) {
            return $this->resErr ($e->getMessage (), $e->getCode ());
        }
    }

    /**
     * 客户基本信息保存
     * @return false|string
     */
    public function saveCustomerInfo() {
        try {
            $params = $this->checkParams ('agent_user_id');
            $CustomerModel = new CustomerModel();
            $data = $CustomerModel->saveCustomerInfo ($params);
            if ($data){
                return $this->resData ('success', []);
            }else{
                return $this->resErr ();
            }

        } catch (Exception $e) {
            return $this->resErr ($e->getMessage (), $e->getCode ());
        }
    }


    /**
     * 客户互动记录
     * @return false|string
     */
    public function getInteractionList(){
        try {
            $params = $this->checkParams ('agent_user_id,page');
            $CustomerModel = new CustomerModel();
            $pageSize=10;
            $data = $CustomerModel->getInteractionList ($params,$pageSize);
            if ($data){
                return $this->resData ('success', $data);
            }else{
                throw new Exception('操作失败', RespCode::PARAMS_ERR);
            }

        } catch (Exception $e) {
            return $this->resErr ($e->getMessage (), $e->getCode ());
        }
    }

    /**
     * 房源互动记录记录
     * @return false|string
     */
    public function getHouseInteractionList(){
        try {
            $params = $this->checkParams ('agent_user_id,page');
            $CustomerModel = new CustomerModel();
            $pageSize=10;
            $data = $CustomerModel->getHouseInteractionList ($params,$pageSize);
            if ($data){
                return $this->resData ('success', $data);
            }else{
                throw new Exception('操作失败', RespCode::PARAMS_ERR);
            }

        } catch (Exception $e) {
            return $this->resErr ($e->getMessage (), $e->getCode ());
        }
    }

    /**
     * 获取全国省份
     * @return false|string
     */
    public function getProvince(){
        try {
            $params = $this->checkParams ('');
            $CustomerModel = new CustomerModel();
            $data = $CustomerModel->getProvince ();
            if ($data){
                return $this->resData ('success', $data);
            }else{
                throw new Exception('操作失败', RespCode::PARAMS_ERR);
            }

        } catch (Exception $e) {
            return $this->resErr ($e->getMessage (), $e->getCode ());
        }
    }


    /**
     * 根据省查询市
     * @return false|string
     */
    public function getCity(){
        try {
            $params = $this->checkParams ('name');
            $CustomerModel = new CustomerModel();
            $data = $CustomerModel->getCity ($params);
            if ($data){
                return $this->resData ('success', $data);
            }else{
                throw new Exception('操作失败', RespCode::PARAMS_ERR);
            }

        } catch (Exception $e) {
            return $this->resErr ($e->getMessage (), $e->getCode ());
        }
    }


    /**
     * 根据市查询区/县
     * @return false|string
     */
    public function getArea(){
        try {
            $params = $this->checkParams ('name');
            $CustomerModel = new CustomerModel();
            $data = $CustomerModel->getArea ($params);
            if ($data){
                return $this->resData ('success', $data);
            }else{
                throw new Exception('操作失败', RespCode::PARAMS_ERR);
            }

        } catch (Exception $e) {
            return $this->resErr ($e->getMessage (), $e->getCode ());
        }
    }

    /**
     * 客户实时推荐房源列表
     * @return false|string
     */
    public function getTimeRechouse(){
        try {
            $params = $this->checkParams ('agent_user_id,page');
            $CustomerModel = new CustomerModel();
            $pageSize=10;
            $data = $CustomerModel->getTimeRechouse ($params,$pageSize);
            return $this->resData ('success', $data);
        } catch (Exception $e) {
            return $this->resErr ($e->getMessage (), $e->getCode ());
        }
    }


}
